const vehicleModel = require("../../database/model-vehicle");
const create = require('./create')
const update = async (input) => {
  if (!Array.isArray(input)) return false;
  console.log(JSON.stringify(input))
  let ids = [];
  for (const v of input) {
    if (v.id) {
      
      await vehicleModel.update(v, {
        where: {
          id: v.id,
        },
      });
    } else {
      let id = await create(v)
      ids.push(id);
    }
  }

  const {count, rows} = await vehicleModel.findAndCountAll()
  return rows.map(it => it.id)
};

module.exports = update;
